// JavaScript Document
function check()
{
	var cond=true;
	if(document.form.radiobutton.value="")
	{
		alert("Please Select your sex.");
		if(cond==true)
		{
			document.form.radiobutton.focus();
		}
		cond=false;
		return false;
	}	
	if(document.form.fname.value==0)
	{
		alert("Please Enter First Name.");
		if(cond==true)
		{
			document.form.fname.focus();
		}
		cond=false;
		return false;
	}
	if(document.form.lname.value.length==0)
	{
		alert("Please Enter Last Name.");
		if(cond==true)
		{
			document.form.lname.focus();
		}
		cond=false;
		return false;
	}	
	if(document.form.day.value.length==0)
	{
		alert("Please Enter Date Of Birth.");
		if(cond==true)
		{
			document.form.day.focus();
		}
		cond=false;
		return false;
	}
	if(document.form.email.value.length==0)
	{
		alert("Please Enter E-Mail.");
		if(cond==true)
		{
			document.form.email.focus();
		}
		cond=false;
		return false;
	}
	if(document.form.add1.value.length==0)
	{
		alert("Please Enter Street Address.");
		if(cond==true)
		{
			document.form.add1.focus();
		}
		cond=false;
		return false;
	}
	if(document.form.postcode.value==0)
	{
		alert("Please Enter Post Code.");
		if(cond==true)
		{
			document.form.postcode.focus();
		}
		cond=false;
		return false;
	}
	if(document.form.city.value.length==0)
	{
		alert("Please Enter city.");
		if(cond==true)
		{
			document.form.city.focus();
		}
		cond=false;
		return false;
	}
	if(document.form.state.value.length==0)
	{
		alert("Please State.");
		if(cond==true)
		{
			document.form.state.focus();
		}
		cond=false;
		return false;
	}
	if(document.form.country.value.length==0)
	{
		alert("Please enter country.");
		if(cond==true)
		{
			document.form.country.focus();
		}
		cond=false;
		return false;
	}
	if(!document.form.terms.checked)
	{
		alert("Read and Agree to Terms and Conditions.");
		if(cond==true)
		{
			document.form.terms.focus();
		}
		cond=false;
		return false;
	}
	


	else if(!checkMail(document.form.email.value))
	{
		alert("Email must contain an email address.\n");
		if(cond==true)
		{
			document.form.email.focus();
		}
		cond=false;
		return false;
	}
	if(document.form.password.value != "" && document.form.cpassword.value != "" ) 
	{
		if(document.form.password.value == document.form.cpassword.value)
		{
			return true;
		}
		else
		{
			alert("Password and Confirm Password does not Match.");
			return false;
		}
	}
	
	if(!IsNumeric(document.form.phone.value))
	{
		alert("Please Enter Numeric value for Phone No.");
		if(cond==true)
		{
			document.form.phone.focus();
		}
		cond=false;
		return false;
			
	}
	if(!IsNumeric(document.form.day.value))
	{
		alert("Please Enter Numeric value for dob.");
		if(cond==true)
		{
			document.form.day.focus();
		}
		cond=false;
		return false;
			
	}
	
	
	var radiobutton;
	radiobutton="";
	
	// check validation for radiobuttn
	for (i=0; i<document.form.radiobutton.length; i++)
	{
		if (document.form.radiobutton[i].checked)
		{
			radio = document.form.radiobutton[i].value;
		}
	}
	if(radiobutton=="")
	{
		alert("Please Select your Sex.");
		return false;
	}
	
}	
function checkMail(email)
{
	var x = email;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) 
	{
	 return true;
	}
	else 
	{
	  return false;
	}
}

//  only insert integer no in Age field.
function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}

